import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;

// file.encoding
public class CharsetDemo {

	public static void main(String[] args) throws UnsupportedEncodingException {
	    // constructor
		Charset.forName("UTF8");
		Charset.defaultCharset();
		Charset.isSupported("UTF8");
	    //System.out.println(Charset.defaultCharset());
	    
	    String s = new String(new byte[]{-58}, Charset.forName("windows-1251"));
	    System.out.println("byte value -58 to string in windows-1251 encoding: " + s);

	    String ss = new String(new byte[]{-58}, Charset.forName("UTF-8"));
	    System.out.println("byte value -58 to string in UTF-8 encoding: " + ss);
/*
		String defaultCharset = Charset.defaultCharset().name();
		System.out.println("Current default charset: " + defaultCharset);

		String str = "Svetlin Nakov <-> ������� �����";
		System.out.printf("str = \"%s\"\n", str);

		byte[] encoded = str.getBytes("ascii");
		System.out.print("encoded = ");
		printArray(encoded);

		String decoded = new String(encoded, "ascii");
		System.out.printf("decoded = \"%s\"\n", decoded);*/
	}

	private static void printArray(byte[] arr) {
		for (byte b : arr) {
			System.out.printf("%x ", b);
		}
		System.out.println();
	}

}
